home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / MacApp Documentation / MacApp AppleLink Messages / MacApp.Tech$ 12⁄22⁄89 / 0249-Re Associating Two F-Dec89 < prev    next >
Encoding:
Text File  |  1989-12-22  |  3.6 KB  |  128 lines  |  [TEXT/GEOL]

  1. Item    8546692                         21-Dec-89        13:55
  2.  
  3. From:   V0230                           Trace, Laurence Kirsh,VAR
  4.  
  5. To:     D5369                           Mgmt Sys Des, Chuck McMath,PRT
  6.  
  7. cc:     MACAPP.TECH$                    MacApp Technical
  8.  
  9. Sub:    re- Associating Two Files
  10.  
  11. Chuck,
  12.  
  13. I had a vaguely similar situation in TRS. There, the application held a STR
  14. resource which was the complete pathname of the folder which held all the data
  15. files. (This was safe since it was on a server and a network administrator kept
  16. the name from changing). The application automatically used that path to open
  17. all document files.
  18.  
  19. What I did was convert the pathname into a working directory number
  20. (gDataWDNum), and passed that to gApplication.OpenOld:
  21.  
  22. {====================================================}
  23. . . .
  24.    {fill in the record used to open the file}
  25.    With FileData Do Begin
  26.    vRefNum := gDataWDNum;
  27.    fType := kDocFileType;
  28.    VersNum := 0;   {obsolete}
  29.    fName := SelectedInfo.FileName
  30.    End;
  31.  
  32.    CatchFailures (fi, HandleOpenFailure);
  33.  
  34.    {open the file as an old file}
  35.    gApplication.OpenOld (cOpen, FileData);
  36.  
  37.    Success (fi);
  38. {====================================================}
  39.  
  40. The code used to initialize that global is given below. The PBOpenWD call is
  41. what you want, I think. Once I change the volume in here, it stays changed, but
  42. I don't think that is necessary for this to work.
  43.  
  44. {====================================================}
  45. {$S AInit}
  46. Procedure InitFileUnit;
  47. {initialize gDataWDNum}
  48.  
  49. Var
  50.     MyWDPB: WDPBRec;   {to find our vol ref number}
  51.     LocalName: Str255; {space for PB calls}
  52.  
  53.     PathName: Str255;
  54.     TempPath: StringHandle;{used to fetch search path resource string}
  55.  
  56. Begin
  57.    If Not gConfiguration.HasHFS
  58.    Then gDataWDNum := 0{not sure this will work, really we shouldn't run in
  59. this case}
  60.  
  61.    Else Begin
  62.    {--- get search path}
  63.    TempPath := GetString (kSearchPathID);
  64.    If TempPath = Nil
  65.    Then PathName := ''
  66.    Else PathName := TempPath^^;
  67.    ReleaseResource (Handle(TempPath));
  68.    {$IFC qDebug}
  69.    Writeln ('Search Path = "',PathName,'"');
  70.    {$ENDC}
  71.  
  72.  
  73.    {--- use search path to set default volume and directory}
  74.    With MyWDPB Do Begin
  75.     ioCompletion := Nil;
  76.     ioNamePtr := @PathName;
  77.     ioVRefNum := -32768;   {means "unknown" see end of TN77}
  78.     ioWDDirID := 0
  79.    End;
  80.  
  81.    If PBHSetVol (@MyWDPB, False) <> noErr Then Begin
  82.    ParamText (PathName, '', '', '');
  83.    StdAlert (kSetVolAlertID)
  84.    {If the SetVol fails then the rest of this code should
  85.     execute on the current directory (where the application is)}
  86.    End;
  87.  
  88.  
  89.    {--- now get the default VRefNum and DirID}
  90.    With MyWDPB Do Begin
  91.     ioCompletion := Nil;
  92.     ioNamePtr := @LocalName
  93.    End;
  94.  
  95.    FailOSErr (PBHGetVol (@myWDPB, False));
  96.  
  97.  
  98.    {--- make a WD from the default VRefNum and DirID}
  99.    With MyWDPB Do Begin
  100.     ioCompletion := Nil;
  101.     ioNamePtr := Nil;
  102.     ioVRefNum := ioWDVRefNum;        {from GetVol call}
  103.     ioWDProcID := LongInt('ERIK'); {see TN 77}
  104.    { ioWDDirID already set}{from GetVol call}
  105.    End;
  106.  
  107.    FailOSErr (PBOpenWD (@MyWDPB, False));
  108.  
  109.  
  110.    {--- finally, what we want: a working directory for the search path}
  111.    gDataWDNum := MyWDPB.ioVRefNum;
  112.  
  113.    {$IFC qDebug}
  114.    ;Writeln ('gDataWDNum = ',gDataWDNum:0);
  115.    {$ENDC}
  116.    End
  117.  
  118. End;   {InitFileUnit}
  119. {=======================================================}
  120.  
  121. I think what you need to do is use your saved file info to create the working
  122. directory number, and then use that to open the files.
  123.  
  124. --John MacVeigh
  125.  
  126. P.S. Merry Christmas from what's left of Trace... err make that IRC-Arlington!
  127.  
  128.